using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.IO;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Shop_Browse_ShopList : Shop, IRequiresSessionState
{
	public string m_place = "";
	public string m_classid = "0";
	public string m_other = "all";
	public string m_bandshop = "0";
	public string m_highshop = "0";
	public string m_commondshop = "";
	public string m_buttonIndex = "0";
	public string m_sorttype = "-1";
	public int s_pageSize = 20;
	public int s_pageIndex = 1;
	public int s_pageCount = 0;
	public string session_id = "";
	protected Shop_UserControls_ClassMapPath ClassMapPath1;
	protected HyperLink alllink;
	protected HyperLink bandshoplink;
	protected HyperLink highshoplink;
	protected Literal ButtonIndex;
	protected Image Page_20;
	protected HyperLink Page20Link;
	protected Image Page_40;
	protected HyperLink Page40Link;
	protected Image Page_80;
	protected HyperLink Page80Link;
	protected DropDownList F_ProductPlace;
	protected DropDownList Sort_Type;
	protected GridView GridView1;
	protected Literal CurrentPage;
	protected LinkButton Pre_Page;
	protected LinkButton FirstPage;
	protected PlaceHolder NumberPageHolder;
	protected LinkButton LastPage;
	protected LinkButton Next_Page;
	protected TextBox GoPageNum;
	protected Button GoPageButton;
	protected Shop_UserControls_ShopDetailSearch ShopDetailSearch1;
	protected Literal ShopClassListLiteral;
	protected HiddenField H_pageIndex;
	protected HiddenField H_pageSize;
	protected HiddenField H_productPlace;
	protected HiddenField H_sortType;
	protected HiddenField H_parentid;
	protected HiddenField H_OtherType;
	protected HiddenField H_PageCount;
	protected ObjectDataSource ObjectDataSource5;
	protected HtmlForm form_1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_PreInit(object sender, EventArgs e)
	{
		try
		{
			Template.BindTemplateToPage(this.Page, "ShopList");
		}
		catch (Exception ex)
		{
			base.WriteTemErrMsg(ex.Message.ToString());
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		base.ShowCityArea();
		this.BandPageParm();
		if (!base.IsPostBack)
		{
			this.session_id = "shop_" + this.Session.SessionID + this.m_other + this.m_classid;
			this.Session["howave_session_id"] = this.session_id;
			this.BindCategoryDataTable(this.GetCacheDataTable(this.session_id + "CategoryTable"), 20, 1);
			this.BindCategoryPage();
		}
		this.ShowPageNumber();
		this.ButtonIndex.Text = this.m_buttonIndex.ToString();
		this.ShopClassListLiteral.Text = this.ShowShopClassList();
	}
	protected void BindCategoryDataTable(DataTable SoucreDataTable, int PageSizes, int PageIndex)
	{
		if (PageIndex < 1)
		{
			PageIndex = 1;
		}
		this.GridView1.PageSize = PageSizes;
		this.GridView1.PageIndex = PageIndex - 1;
		this.GridView1.DataSource = SoucreDataTable;
		this.GridView1.DataBind();
		this.s_pageCount = SoucreDataTable.Rows.Count / PageSizes + 1;
		this.H_PageCount.Value = this.s_pageCount.ToString();
	}
	private void BuildCacheDataTable(string CahceTableName, DataTable CacheTable)
	{
		base.Cache.Insert(CahceTableName, CacheTable, null, DateTime.Now.AddMinutes(1.0), TimeSpan.Zero);
	}
	private DataTable GetCacheDataTable(string CahceTableName)
	{
		DataTable result;
		if (base.Cache[CahceTableName] != null)
		{
			DataTable dataTable = (DataTable)base.Cache[CahceTableName];
			result = dataTable;
		}
		else
		{
			Shop_Shop shop_Shop = new Shop_Shop();
			DataTable dataTable2 = shop_Shop.SearchShopPerPage(this.s_pageSize, this.s_pageIndex, 0, "", "", int.Parse(this.m_classid), "", "", this.m_place, "", int.Parse(this.m_sorttype), this.m_commondshop, this.m_highshop, this.m_bandshop, "");
			this.BuildCacheDataTable(CahceTableName, dataTable2);
			result = dataTable2;
		}
		return result;
	}
	protected void BindCategoryPage()
	{
	}
	protected void PagerButton_Click(object sender, CommandEventArgs e)
	{
		DataTable sortAndPlcaeSelectChanged = this.GetSortAndPlcaeSelectChanged();
		this.s_pageCount = sortAndPlcaeSelectChanged.Rows.Count / this.s_pageSize + 1;
		string commandName = e.CommandName;
		if (commandName != null)
		{
			if (commandName == "Pre")
			{
				if (this.s_pageIndex > 0)
				{
					this.s_pageIndex--;
				}
				goto IL_129;
			}
			if (commandName == "Next")
			{
				if (this.s_pageIndex < this.s_pageCount - 1)
				{
					this.s_pageIndex++;
				}
				goto IL_129;
			}
			if (commandName == "Last")
			{
				this.s_pageIndex = this.s_pageCount;
				goto IL_129;
			}
			if (commandName == "First")
			{
				this.s_pageIndex = 1;
				goto IL_129;
			}
			if (commandName == "GoPage")
			{
				this.s_pageIndex = Convert.ToInt32(this.GoPageNum.Text);
				goto IL_129;
			}
		}
		this.s_pageIndex = Convert.ToInt32(e.CommandName);
		IL_129:
		this.H_pageIndex.Value = this.s_pageIndex.ToString();
		this.BindCategoryDataTable(sortAndPlcaeSelectChanged, this.s_pageSize, this.s_pageIndex);
		this.BindCategoryPage();
		this.ShowPageNumber();
	}
	protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			Image image = (Image)e.Row.FindControl("ShopImage");
			if (!File.Exists(base.Server.MapPath(image.ImageUrl.Replace("/", "\\"))))
			{
				image.ImageUrl = "/Shop/Images/show_nopic.gif";
				image.Attributes.Add("large_src", image.ImageUrl);
			}
			Literal literal = (Literal)e.Row.FindControl("BandShop");
			if (literal.Text == "2")
			{
				literal.Text = "<a href='#'><img src=\"/Shop/Images/shop_identify.gif\"/></a>";
			}
			else
			{
				literal.Visible = false;
			}
			bool flag = false;
			bool flag2 = false;
			DataRow shopconfig = base.shopconfig;
			if (shopconfig["ShowQQ"].ToString() == "1")
			{
				flag = true;
			}
			if (shopconfig["ShowWW"].ToString() == "1")
			{
				flag2 = true;
			}
			Image image2 = (Image)e.Row.FindControl("QQImage");
			if (flag && image2.ImageUrl != "")
			{
				image2.ImageUrl = "http://wpa.qq.com/pa?p=1:" + image2.ImageUrl + ":4";
			}
			else
			{
				image2.Visible = false;
			}
			Image image3 = (Image)e.Row.FindControl("TaobaoImage");
			if (flag2 && image3.ImageUrl != "")
			{
				image3.ImageUrl = "http://amos1.taobao.com/online.ww?v=2&amp;uid=" + base.Server.UrlEncode(image3.ImageUrl) + "&s=2";
			}
			else
			{
				image3.Visible = false;
			}
		}
	}
	protected void GridView1_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		DataTable sortAndPlcaeSelectChanged = this.GetSortAndPlcaeSelectChanged();
		this.GridView1.PageIndex = e.NewPageIndex;
		this.GridView1.PageSize = this.s_pageSize;
		this.GridView1.DataSource = sortAndPlcaeSelectChanged;
		this.GridView1.DataBind();
		this.BindCategoryPage();
	}
	protected void ChangePageSize(object sender, CommandEventArgs e)
	{
		string commandName = e.CommandName;
		if (commandName != null)
		{
			if (!(commandName == "Page_20"))
			{
				if (!(commandName == "Page_40"))
				{
					if (commandName == "Page_80")
					{
						this.H_pageSize.Value = "80";
					}
				}
				else
				{
					this.H_pageSize.Value = "40";
				}
			}
			else
			{
				this.H_pageSize.Value = "20";
			}
		}
		this.s_pageSize = Convert.ToInt32(this.H_pageSize.Value);
		this.ChanagePageButton(this.s_pageSize);
		this.BindCategoryDataTable(this.GetSortAndPlcaeSelectChanged(), this.s_pageSize, 1);
		this.BindCategoryPage();
	}
	protected void ChanagePageButton(int PageSize)
	{
		if (PageSize != 20)
		{
			if (PageSize != 40)
			{
				if (PageSize == 80)
				{
					this.Page_20.ImageUrl = "../Images/page_20.gif";
					this.Page_40.ImageUrl = "../Images/page_40.gif";
					this.Page_80.ImageUrl = "../Images/page_80_select.gif";
				}
			}
			else
			{
				this.Page_20.ImageUrl = "../Images/page_20.gif";
				this.Page_40.ImageUrl = "../Images/page_40_select.gif";
				this.Page_80.ImageUrl = "../Images/page_80.gif";
			}
		}
		else
		{
			this.Page_20.ImageUrl = "../Images/page_20_select.gif";
			this.Page_40.ImageUrl = "../Images/page_40.gif";
			this.Page_80.ImageUrl = "../Images/page_80.gif";
		}
	}
	protected void SortAndPlaceSelectIndexChange(object sender, EventArgs e)
	{
		this.H_pageIndex.Value = "1";
		this.BindCategoryDataTable(this.GetSortAndPlcaeSelectChanged(), this.s_pageSize, 1);
		this.BindCategoryPage();
		this.ShowPageNumber();
	}
	protected DataTable GetSortAndPlcaeSelectChanged()
	{
		int num = Convert.ToInt32(this.Sort_Type.SelectedValue);
		string text = "";
		if (this.F_ProductPlace.SelectedValue != "-1")
		{
			text = this.F_ProductPlace.SelectedValue;
		}
		string sort;
		switch (num)
		{
		case 10:
			sort = "ShopCredit desc";
			goto IL_88;
		case 12:
			sort = "ShopProductNum desc";
			goto IL_88;
		}
		sort = "ShopCredit desc";
		IL_88:
		this.H_productPlace.Value = text;
		this.H_sortType.Value = this.Sort_Type.SelectedValue;
		this.m_place = text;
		this.session_id = this.Session.SessionID;
		string cahceTableName = this.session_id + "CategoryTable";
		DataTable cacheDataTable = this.GetCacheDataTable(cahceTableName);
		DataTable dataTable = cacheDataTable.Copy();
		DataTable result;
		if (cacheDataTable != null)
		{
			if (text != "")
			{
				DataRow[] array = cacheDataTable.Select("(ShopAddress like '%" + text + "%')");
				dataTable.Clear();
				for (int i = 0; i < array.Length; i++)
				{
					dataTable.ImportRow(array[i]);
				}
			}
			DataView defaultView = dataTable.DefaultView;
			defaultView.Sort = sort;
			result = defaultView.ToTable();
		}
		else
		{
			result = null;
		}
		return result;
	}
	private void BandPageParm()
	{
		if (base.Request["ParentID"] != null && Text.IsNumber(base.Request["ParentID"]))
		{
			this.m_classid = base.Request["ParentID"];
		}
		if (base.Request["othertype"] != null && base.Request["othertype"] != "")
		{
			this.m_other = base.Request["othertype"];
		}
		this.m_sorttype = this.Sort_Type.SelectedValue;
		if (this.F_ProductPlace.SelectedValue != "-1")
		{
			this.m_place = this.F_ProductPlace.SelectedValue;
		}
		this.s_pageSize = Convert.ToInt32(this.H_pageSize.Value);
		this.s_pageIndex = Convert.ToInt32(this.H_pageIndex.Value);
		if (string.IsNullOrEmpty(this.m_other))
		{
			this.H_OtherType.Value = this.m_other;
		}
		if (string.IsNullOrEmpty(this.m_sorttype))
		{
			this.H_sortType.Value = this.m_sorttype;
		}
		if (this.m_sorttype != "")
		{
			int num = -1;
			try
			{
				num = Convert.ToInt32(this.m_sorttype);
			}
			catch
			{
			}
			if (num >= -1 && num <= 8 && num != 0)
			{
				this.Sort_Type.SelectedValue = this.m_sorttype;
			}
		}
		else
		{
			this.m_sorttype = "-1";
		}
		string text = base.Request["othertype"];
		if (text != null)
		{
			if (text == "band")
			{
				this.m_bandshop = "1";
				this.m_buttonIndex = "1";
				goto IL_285;
			}
			if (text == "high")
			{
				this.m_highshop = "1";
				this.m_buttonIndex = "2";
				goto IL_285;
			}
		}
		this.m_commondshop = "1";
		this.m_bandshop = "1";
		this.m_highshop = "1";
		this.m_buttonIndex = "0";
		IL_285:
		this.alllink.NavigateUrl = "ShopList.aspx?" + this.GetBindQuerryString("othertype", "all", true);
		this.bandshoplink.NavigateUrl = "ShopList.aspx?" + this.GetBindQuerryString("othertype", "band", true);
		this.highshoplink.NavigateUrl = "ShopList.aspx?" + this.GetBindQuerryString("othertype", "high", true);
		this.H_pageSize.Value = this.s_pageSize.ToString();
		this.H_OtherType.Value = this.m_other;
		this.H_productPlace.Value = this.m_place;
		this.H_sortType.Value = this.m_sorttype;
		this.H_parentid.Value = this.m_classid;
		this.H_pageIndex.Value = this.s_pageIndex.ToString();
		if (!string.IsNullOrEmpty(this.m_classid))
		{
			Shop_Class shop_Class = new Shop_Class();
			string classNameByClassID = shop_Class.GetClassNameByClassID(int.Parse(this.m_classid));
		}
	}
	protected string GetBindQuerryString(string RequestName, string sValue, bool PageIsFirst)
	{
		string str = this.m_classid;
		string str2 = this.m_other;
		string sorttype = this.m_sorttype;
		string text = this.s_pageSize.ToString();
		string text2 = this.s_pageIndex.ToString();
		if (RequestName != null)
		{
			if (!(RequestName == "othertype"))
			{
				if (RequestName == "Parentid")
				{
					str = sValue;
				}
			}
			else
			{
				str2 = sValue;
			}
		}
		if (PageIsFirst)
		{
		}
		return "&othertype=" + str2 + "&ParentID=" + str;
	}
	public void ShowPageNumber()
	{
		int num = 7;
		int num2 = 0;
		int num3 = 0;
		bool flag = false;
		bool flag2 = false;
		this.s_pageIndex = Convert.ToInt32(this.H_pageIndex.Value);
		this.s_pageCount = Convert.ToInt32(this.H_PageCount.Value);
		this.CurrentPage.Text = this.s_pageIndex.ToString() + "/" + this.s_pageCount.ToString();
		this.LastPage.Text = this.s_pageCount.ToString();
		if (this.s_pageIndex == 1)
		{
			this.Pre_Page.Text = "<img src='../Images/pre_page_0.gif' style='border:0;vertical-align:middle;height:18px'/>";
		}
		else
		{
			this.Pre_Page.Text = "<img src='../Images/pre_page_1.gif' style='border:0;vertical-align:middle;height:18px'/>";
		}
		if (this.s_pageIndex >= this.s_pageCount)
		{
			this.Next_Page.Text = "<img src='../Images/next_page_0.gif' style='border:0;vertical-align:middle;height:18px'/>";
			this.s_pageIndex = this.s_pageCount;
		}
		if (this.s_pageCount <= num)
		{
			num2 = 2;
			num3 = this.s_pageCount - 1;
		}
		else
		{
			int num4 = num / 2;
			int num5 = num4;
			if (this.s_pageIndex + num4 > this.s_pageCount)
			{
				for (int i = num4; i >= -num5; i--)
				{
					if (this.s_pageIndex + i < this.s_pageCount)
					{
						num2 = this.s_pageIndex - num5;
						num3 = this.s_pageIndex + i;
						break;
					}
					num3 = this.s_pageCount - 1;
					num5++;
				}
			}
			else
			{
				for (int i = -num4; i <= num5; i++)
				{
					if (this.s_pageIndex + i >= 2)
					{
						num2 = this.s_pageIndex + i;
						num3 = this.s_pageIndex + num5;
						break;
					}
					num2 = 2;
					num5++;
				}
			}
		}
		this.NumberPageHolder.Controls.Clear();
		if (flag)
		{
			Literal literal = new Literal();
			literal.Text = "...&nbsp";
			this.NumberPageHolder.Controls.Add(literal);
		}
		for (int j = num2; j <= num3; j++)
		{
			if (j != this.s_pageIndex)
			{
				LinkButton linkButton = new LinkButton();
				linkButton.Command += new CommandEventHandler(this.PagerButton_Click);
				linkButton.Text = (linkButton.CommandName = j.ToString());
				linkButton.ID = "page" + j.ToString();
				this.NumberPageHolder.Controls.Add(linkButton);
			}
			else
			{
				Literal literal = new Literal();
				literal.Text = "<b>" + j.ToString() + "</b>";
				this.NumberPageHolder.Controls.Add(literal);
			}
		}
		if (flag2)
		{
			Literal literal = new Literal();
			literal.Text = "...";
			this.NumberPageHolder.Controls.Add(literal);
		}
		this.ChanagePageButton(this.s_pageSize);
	}
	public string ShowShopClassList()
	{
		string text = "";
		Shop_Class shop_Class = new Shop_Class();
		DataTable rootClass = shop_Class.GetRootClass();
		if (rootClass != null && rootClass.Rows.Count > 0)
		{
			for (int i = 0; i < rootClass.Rows.Count; i++)
			{
				text = text + "<div id=ShopsDigital class=ShopCateL0>" + Environment.NewLine;
				text = text + "  <div class=hackBox></div>" + Environment.NewLine;
				string text2 = text;
				text = string.Concat(new string[]
				{
					text2,
					"     <h2>",
					rootClass.Rows[i]["ClassName"].ToString(),
					"</h2>",
					Environment.NewLine
				});
				text = text + "         <ul class=' CategoryListNormalLevel1'>" + Environment.NewLine;
				text2 = text;
				text = string.Concat(new string[]
				{
					text2,
					"             <li><a href='ShopList.aspx?ParentID=",
					rootClass.Rows[i]["Classid"].ToString(),
					"'>",
					rootClass.Rows[i]["ClassName"].ToString(),
					"</a></li>",
					Environment.NewLine
				});
				text += "</ul></div>";
			}
		}
		return text;
	}
}
